package com.controller.base;

import com.common.anntation.Log;
import com.common.emums.BusinessType;
import com.common.utils.EntityConversionUtil;
import com.github.pagehelper.PageInfo;
import com.model.base.PageResult;
import com.model.base.Result;
import com.model.domain.base.GetBasePartInfoDO;
import com.model.dto.base.part.GetPartListDTO;
import com.model.pojo.base.BasePartInfo;
import com.model.vo.base.part.getPartList.GetPartListVO;
import com.service.base.BasePartInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @Description
 * @Author tm
 * @Date 2023-09-09 15:43
 **/
@Api(tags = {"备件管理"})
@Slf4j
@RestController
@RequestMapping("/v1/base/part")
@RequiredArgsConstructor
public class PartInfoController {
    private final BasePartInfoService basePartInfoService;
    @Log(title = "备件管理-备件列表", businessType = BusinessType.INSERT)
    @ApiOperation(value = "备件列表")
    @PostMapping("/getPartList")
    public Result<PageResult<List<GetPartListVO>>> getPartList(@RequestBody @Valid GetPartListDTO dto){
        List<GetPartListVO> voList = new ArrayList<>();
        GetBasePartInfoDO getBasePartInfoDO = EntityConversionUtil.copy(dto,GetBasePartInfoDO.class);
        List<BasePartInfo> list = basePartInfoService.getPageList(getBasePartInfoDO);
        voList = EntityConversionUtil.copyList(list,GetPartListVO.class);
        PageInfo<BasePartInfo> pageInfo = new PageInfo<>(list);
        PageResult<List<GetPartListVO>> build = PageResult.<List<GetPartListVO>>builder().result(voList).pageInfo(pageInfo).build();
        return Result.suc(build);
    }
}
